﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ZhwangTool
{
   public class MyFileInfo: INotifyPropertyChanged
    {
        long size = 0;
        string name;
        uint crc32 = 0;
        string md5;
        string hash;
        string groupTag;

        

        public string ErrMessage { get; set; }
     
        public MyFileInfo(string nameStr)
        {
            name = nameStr;

            groupTag = "GroupTag";
        }
        //构造函数
        //从源头上控制myFileInfo对象文件是存在的
        string givenFolder;

        public MyFileInfo(string nameStr, string foderStr):this(nameStr)
        {
            //name = nameStr;

            //groupTag = "GroupTag";

            givenFolder = foderStr;

        }
        public override string ToString()
        {
            //
            //item.Remove(0, textBox1.Text.Length
            return Name.Remove(0,GivenFolder.Length);
        }

        public string GetDirectoryName()
        {
            FileInfo fileInfo = new FileInfo(name);

            return fileInfo.DirectoryName;

        }

        string shortName;
        bool sign;
        int tag;

        public string Md5 { get => md5; set => md5 = value; }
        public string Hash { get => hash; set => hash = value; }
        public uint Crc32 { get => crc32; set => crc32 = value; }
        public long Size { get => size; set => size = value; }
        public string GivenFolder { get => givenFolder; set => givenFolder = value; }
        public string Name { get => name;}
        public string ShortName {

            get => Name.Substring(GivenFolder.Length);

            set => shortName = value;
            
        }

        public bool Sign
        {
            get { return sign; }
            set
            {
                sign = value;
                NotifyPropertyChanged("Sign");
            }
        }

        public DateTime LastWriteTime
        {
            get
            {
                return new FileInfo(Name).LastWriteTime ;

            }
        }

        public int Tag { get => tag; set => tag = value; }

        public string SizeInMb
        {
            get
            {
                return (Size/1024.0/1024.0).ToString("#0.000");

            }
        }

        public string GroupTag { get => groupTag; }

        public event PropertyChangedEventHandler PropertyChanged;

        private void NotifyPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }


    }
}
